﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Common;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.User_Enum;
public partial class Users_RegisterTwo : Pub_Label
{
    protected Users UserBll = new Users();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.Radio_Sex.DataTextField = "EnumDisplayText";
            this.Radio_Sex.DataValueField = "EnumDisplayText";
            this.Radio_Sex.SelectedIndex = 0;
            this.Radio_Sex.DataSource = EnumDescription.GetFieldTexts(typeof(Sex_Enum), EnumDescription.SortType.Rank);
            this.Radio_Sex.DataBind();

            this.StrQ1.DataTextField = "EnumDisplayText";
            this.StrQ1.DataValueField = "EnumValueStr";
            this.StrQ1.DataSource = EnumDescription.GetFieldTexts(typeof(Question_Enum), EnumDescription.SortType.Rank);
            this.StrQ1.DataBind();
            ListItem Itm = new ListItem("请选择密码提示问题？", "");
            Itm.Selected = true;
            this.StrQ1.Items.Add(Itm);
         }
        IsNoReg();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        Users_Model model = new Users_Model();
        model.UserName = Txt_RegName.Text.ToString();
        model.Pwd = EncryptString.md5(Txt_pwd.Text.Trim());
        model.Sex = Radio_Sex.SelectedValue;
        int p = 0;
        if (Request["provice"] != null)
        {
            p = StringHelper.isNumber_int(Request["provice"].ToString());
        }
        model.Province = p;
        int c = 0;
        if (Request["city"] != null)
        {
            c = StringHelper.isNumber_int(Request["city"].ToString());
        }
        model.City = c;
        model.Quesion = StrQ1.SelectedValue.ToString();
        model.Answer = Txt_Ans.Text.ToString();
        model.UserEmail = Txt_Mail.Text.ToString();
        model.Birthday = Txt_Brith.Text.ToString();
        model.UserMobile = Txt_Moblie.Text.ToString();
        model.HomePage = Txt_HomePage.Text.ToString();
        model.QQ = Txt_QQ.Text.ToString();
        model.Msn = Txt_Msn.Text.ToString();

        string Errstr = "";
        if (configInfo.UserRegAdminCheck == 1)
        {
            model.LockUser = 1;
            model.Readme = DateTime.Now.ToString() + "用户注册，需要管理员审核";
            Errstr = "请等待管理员审核。";

        }
        model.Point = configInfo.UserRegPoint;
        model.Integral = configInfo.UserRegIntegral;
        if (UserBll.Add(model) > 0)
        {
            Response.Write("<script>alert('用户注册成功！" + Errstr + "');location.href='Login.Aspx?ReUrl=" + Server.UrlEncode(configInfo.InstallDir + "default.aspx") + "'</script>");
            Response.End();
        }
        else
        {
            Response.Write("<script>alert('用户注册失败，请认真填写必填项！');history.back()</script>");
            Response.End();
        }


    }
    protected void Radio_Sex_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
